package com.bw.parkingspace_module.parkingvr

import android.graphics.Color
import android.os.Bundle
import android.view.View
import android.widget.TextView
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.BarUtils
import com.bw.parkingspace_module.R
import com.bw.parkingspace_module.databinding.ActivityParkingvrBinding
import com.bw.parkingspace_module.parking.entity.ParkingValueEntity
import com.kf.common.entity.EventBusEntity
import com.kf.common.entity.EventBusType
import com.kf.common.mvi.view.BaseActivity
import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode
import org.koin.androidx.viewmodel.ext.android.viewModel

@Route(path = "/parking/parkingvractivity")
class ParkingVRActivity : BaseActivity<ActivityParkingvrBinding, ParkingVRViewModel>() {

    @Autowired
    lateinit var parkingEntity: ParkingValueEntity

    override fun createViewModel(): ParkingVRViewModel {
        return viewModels<ParkingVRViewModel>().value
    }

    override fun createViewBind(): ActivityParkingvrBinding {
        return ActivityParkingvrBinding.inflate(inflater)
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        ARouter.getInstance().inject(this)
        BarUtils.setStatusBarColor(this, Color.parseColor("#2196F3"))
        EventBus.getDefault().register(this)
        mView.parkingvrText.text = "车位预览"
        mView.parkingvrBack.setOnClickListener {
            finish()
        }
        mView.startParkingedit.setOnClickListener {
            ARouter.getInstance().build("/parking/parkingeditactivity")
                .withSerializable("parkingEntity", parkingEntity).navigation()
        }
    }

    override fun onDestroy() {
        super.onDestroy()
        EventBus.getDefault().unregister(this)
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    fun eventBus(eventBusEntity: EventBusEntity) {
        if (eventBusEntity.action == EventBusType.PARKING_SUCCESS) {
            finish()
        }
    }

}